//
//  MineViewController.m
//  ieGou
//
//  Created by 潮汐 on 15-1-28.
//  Copyright (c) 2015年 chaox. All rights reserved.
//

#import "MineViewController.h"
#import "LandingViewController.h"
#import "MyOrderViewController.h"
#import "BulkOrderViewController.h"
#import "BookingOrderViewController.h"
#import "WaitingCommentsViewController.h"
#import "RecommendedViewController.h"
#import "MyCouponViewController.h"
#import "ServiceCenterViewController.h"
#import "MyCollectionViewController.h"

@interface MineViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)NSMutableArray *array1;
@property (nonatomic, retain)NSMutableArray *array2;
@property (nonatomic, retain)NSMutableArray *array3;

@property (nonatomic, retain)UITableView *tableView;


@end

@implementation MineViewController

- (void)dealloc
{
    [_array1 release];
    [_array2 release];
    [_array3 release];
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 设置标题
    self.navigationItem.title = @"我的";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:95/255.0 green:207/255.0 blue:173/255.0 alpha:1];
    
    // 添加数组成员
    self.array1 = [NSMutableArray arrayWithObjects:@"我的订单", @"团购订单", @"预定订单", @"等待点评", nil];
    self.array2 = [NSMutableArray arrayWithObjects:@"每日推荐", nil];
    self.array3 = [NSMutableArray arrayWithObjects:@"我的优惠券", @"服务中心", nil];
    
    //tableView
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    // 添加一个HeaderView
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 200)];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"10001.jpg"]];
        imageView.frame = CGRectMake(0, 0, 375, 200);
    self.tableView.tableHeaderView = view1;
        [view1 addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    [self.view addSubview:_tableView];
    [imageView release];
    
    //  在图片上面设置按钮
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 setImage:[UIImage imageNamed:@"10003.jpg"] forState:UIControlStateNormal];
    button1.frame = CGRectMake(0, 140, 187.5, 62);
    [button1 addTarget:self action:@selector(buttonClicked1:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
//    [button2 setBackgroundImage:[UIImage imageNamed:@"10002"] forState:UIControlStateNormal];
    [button2 setImage:[UIImage imageNamed:@"10002.jpg"] forState:UIControlStateNormal];
    button2.frame = CGRectMake(187.5, 140, 187.5, 62);
    [button2 addTarget:self action:@selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:button2];
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button3 setTitle:@"登陆" forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont fontWithName:@"登陆" size:13];
    button3.frame = CGRectMake(150, 80, 80, 80);
    button3.userInteractionEnabled = YES;
    [button3 addTarget:self action:@selector(buttonClicked3:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:button3];
    
    [_tableView release];
    

}

- (void)buttonClicked1:(UIButton *)button
{
    
}


- (void)buttonClicked2:(UIButton *)button
{
    MyCollectionViewController *myCollectionVC = [[MyCollectionViewController alloc]  init];
    [self.navigationController pushViewController:myCollectionVC animated:YES];
    myCollectionVC.title = @"我的收藏";
}

- (void)buttonClicked3:(UIButton *)button
{
    LandingViewController *landingVC = [[LandingViewController alloc] init];
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:landingVC];
    landingVC.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
//    [self.navigationController pushViewController:landingVC animated:YES];
    [self presentViewController:navc animated:YES completion:^{
        
    }];
}

// 重用池
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"Mario";
    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:str];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str] autorelease];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = [self.array1 objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 1) {
        cell.textLabel.text = [self.array2 objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 2) {
        cell.textLabel.text = [self.array3 objectAtIndex:indexPath.row];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

// 每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.array1.count;
    }
    if (section == 1) {
        return self.array2.count;
    }
    else
        return self.array3.count;
}


// 分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

// 分区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1.f;
}

// 分区尾
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 12.f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            MyOrderViewController *myOrderVC = [[MyOrderViewController alloc] init];
            [self.navigationController pushViewController:myOrderVC animated:YES];
            myOrderVC.title = @"我的订单";
        }
        if (indexPath.row == 1) {
            BulkOrderViewController *bulkOrderVC = [[BulkOrderViewController alloc] init];
            [self.navigationController pushViewController:bulkOrderVC animated:YES];
            bulkOrderVC.title = @"团购订单";
        }
        if (indexPath.row == 2) {
            BookingOrderViewController *bookingOrderVC = [[BookingOrderViewController alloc] init];
            [self.navigationController pushViewController:bookingOrderVC animated:YES];
            bookingOrderVC.title = @"预订订单";
        }
        if (indexPath.row == 3) {
            WaitingCommentsViewController *waitingCommentsVC = [[WaitingCommentsViewController alloc] init];
            [self.navigationController pushViewController:waitingCommentsVC animated:YES];
            waitingCommentsVC.title = @"等待点评";
        }
    }
    if (indexPath.section == 1) {
        RecommendedViewController *reconmmendedVC = [[RecommendedViewController alloc] init];
        [self.navigationController pushViewController:reconmmendedVC animated:YES];
        reconmmendedVC.title = @"每日推荐";
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            MyCouponViewController *myCouponVC = [[MyCouponViewController alloc] init];
            [self.navigationController pushViewController:myCouponVC animated:YES];
            myCouponVC.title = @"我的优惠券";
        }
        if (indexPath.row == 1) {
            ServiceCenterViewController *serviceCenterVC = [[ServiceCenterViewController alloc] init];
            [self.navigationController pushViewController:serviceCenterVC animated:YES];
            serviceCenterVC.title = @"服务中心";
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
